package com.ruoyi.web.controller.tongban;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tongban.domain.UsrMember;
import com.ruoyi.tongban.service.IUsrMemberService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户端使用Controller
 * 
 * @author ruoyi
 * @date 2021-08-05
 */
@RestController
@RequestMapping("/tongban/member")
public class UsrMemberController extends BaseController
{
    @Autowired
    private IUsrMemberService usrMemberService;

    /**
     * 查询客户端使用列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(UsrMember usrMember)
    {
        startPage();
        List<UsrMember> list = usrMemberService.selectUsrMemberList(usrMember);
        return getDataTable(list);
    }

    /**
     * 导出客户端使用列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:member:export')")
    @Log(title = "客户端使用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UsrMember usrMember)
    {
        List<UsrMember> list = usrMemberService.selectUsrMemberList(usrMember);
        ExcelUtil<UsrMember> util = new ExcelUtil<UsrMember>(UsrMember.class);
        return util.exportExcel(list, "member");
    }

    /**
     * 获取客户端使用详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:member:query')")
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId)
    {
        return AjaxResult.success(usrMemberService.selectUsrMemberById(memberId));
    }

    /**
     * 新增客户端使用
     */
    @PreAuthorize("@ss.hasPermi('tongban:member:add')")
    @Log(title = "客户端使用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UsrMember usrMember)
    {
        return toAjax(usrMemberService.insertUsrMember(usrMember));
    }

    /**
     * 修改客户端使用
     */
    @PreAuthorize("@ss.hasPermi('tongban:member:edit')")
    @Log(title = "客户端使用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UsrMember usrMember)
    {
        return toAjax(usrMemberService.updateUsrMember(usrMember));
    }

    /**
     * 删除客户端使用
     */
    @PreAuthorize("@ss.hasPermi('tongban:member:remove')")
    @Log(title = "客户端使用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds)
    {
        return toAjax(usrMemberService.deleteUsrMemberByIds(memberIds));
    }
}
